
package com.joysuch.wwyt.core.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.joysuch.wwyt.core.security.ShiroUser;
import com.joysuch.wwyt.core.support.Context;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.BeanFactory;

/**
 * SiteFilter
 * 
 * 
 */
public class BackSiteFilter implements Filter {
    private BeanFactory beanFactory;

    public BackSiteFilter(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    public static final String SUB_SYSTEM_KEY = "_sub_system";

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        // Context.setCurrentSubSystem(resolveSubSystem(request, response));
        ShiroUser principal = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
        Context.setCurrentUser(principal);
        chain.doFilter(request, response);
        // Context.resetCurrentSubSystem();
        Context.resetCurrentUser();
        // Context.resetCurrentSubSystem();
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void destroy() {
    }

}
